<?php $this->load->view('common/header'); ?>
<?php $this->load->view('common/menu'); ?>
    <script>
        (function ($) {
            $.extend({
                UrlGetParams: function (m) {
                    var sValue = location.search.match(new RegExp("[\?\&]" + m + "=([^\&]*)(\&?)", "i"));
                    return sValue ? sValue[1] : sValue;
                },
                UrlUpdateParams: function (url, name, value) {
                    var r = url;
                    if (r != null && r != 'undefined' && r != "") {
                        value = encodeURIComponent(value);
                        var reg = new RegExp("(^|)" + name + "=([^&]*)(|$)");
                        var tmp = name + "=" + value;
                        if (url.match(reg) != null) {
                            r = url.replace(eval(reg), tmp);
                        }
                        else {
                            if (url.match("[\?]")) {
                                r = url + "&" + tmp;
                            } else {
                                r = url + "?" + tmp;
                            }
                        }
                    }
                    return r;
                },
                UrlDelParams: function (name) {
                    var loca = window.location;
                    var baseUrl = loca.origin + loca.pathname + "?";
                    var query = loca.search.substr(1);
                    if (query.indexOf(name) > -1) {
                        var obj = {}
                        var arr = query.split("&");
                        for (var i = 0; i < arr.length; i++) {
                            arr[i] = arr[i].split("=");
                            obj[arr[i][0]] = arr[i][1];
                        }
                        ;
                        delete obj[name];
                        var url = baseUrl + JSON.stringify(obj).replace(/[\"\{\}]/g, "").replace(/\:/g, "=").replace(/\,/g, "&");
                        return url
                    }

                    return window.location.href;
                }
            });
        })(jQuery);

        function listSearch(key, value) {
            var url = $.UrlDelParams("per_page");
            var url = $.UrlUpdateParams(url, key, value);
            console.log(url);
            window.location.href = url;
        }

        // 分类多选触发查询
        function checkBox(key, value) {
            var checkID = "0,";//定义一个空数组
            $("input[name='category']:checked").each(function (i) {//把所有被选中的复选框的值存入数组
                var value = $(this).val();
                checkID += value + ",";
            });
            listSearch(key, checkID);
        }

        // 建筑面积移出光标触发查询
        function areaBox() {
            var areaStart = $("#areaStart").val();
            var areaEnd = $("#areaEnd").val();
            if (areaStart == '' || undefined) {
                return false; //没有初始值不查
            }
            if (areaEnd == '' || undefined) {
                listSearch(key, areaStart);
            } else {
                value = areaStart + "," + areaEnd;
                listSearch('area', value);
            }
        }

        // 价格范围移出光标触发查询
        function priceBox() {
            var priceStart = $("#priceStart").val();
            var priceEnd = $("#priceEnd").val();
            if (priceStart == '' || undefined) {
                return false; //没有初始值不查
            }
            if (priceEnd == '' || undefined) {
                listSearch(key, priceStart);
            } else {
                value = priceStart + "," + priceEnd;
                listSearch('price', value);
            }
        }

        // 附加选项查询
        function attachBox(key) {
            if ($("input[name='" + key + "']").prop('checked')) {
                listSearch(key, 1);
            } else {
                listSearch(key, 0);
            }
        }

        // 空间查询
        function spaceBox() {
            var spaceStart = $("#spaceStart").val();
            var spaceEnd = $("#spaceEnd").val();
            if (spaceStart == '' || undefined) {
                return false; //没有初始值不查
            }
            if (spaceEnd == '' || undefined) {
                listSearch(key, spaceStart);
            } else {
                value = spaceStart + "," + spaceEnd;
                listSearch('space', value);
            }
        }

        // 费率
        function rateBox() {
            var rateStart = $("#rateStart").val();
            var rateEnd = $("#rateEnd").val();
            if (rateStart == '' || undefined) {
                return false; //没有初始值不查
            }
            if (rateEnd == '' || undefined) {
                listSearch(key, rateStart);
            } else {
                value = rateStart + "," + rateEnd;
                listSearch('rate', value);
            }
        }

        // 状态
        function statusBox(status) {
            listSearch('status', status);
        }

        function orderBox(val) {
            listSearch('order', val);
        }


        $(function () {
            $("#search_by").click(function () {

                var keywords = $("#keywords").val();
                listSearch('keyword', keywords);
            });
            $("#clear_search").click(function () {
                var loca = window.location;
                var baseUrl = loca.origin + loca.pathname + "?";
                var obj = {};
                var query = loca.search.substr(1);
                var arr = query.split("&");
                for (var i = 0; i < arr.length; i++) {
                    arr[i] = arr[i].split("=");
                    obj[arr[i][0]] = arr[i][1];
                }
                ;
                delete obj['category'];
                delete obj['area'];
                delete obj['price'];
                delete obj['real'];
                delete obj['real'];
                delete obj['auction'];
                delete obj['distressed'];
                delete obj['space'];
                delete obj['rate'];
                var url = baseUrl + JSON.stringify(obj).replace(/[\"\{\}]/g, "").replace(/\:/g, "=").replace(/\,/g, "&");
                window.location.href = url;
            });
        });
    </script>
    <style>
        #wrap {
            display: none;
        }

        .page {
            display: block;
            overflow: hidden;
            margin: 40px auto 0;
            text-align: center;
        }

        .page li {
            display: inline-block;
            vertical-align: top;
        }

        .page a {
            display: inline-block;
            margin-left: 5px;
            vertical-align: top;
            padding: 0 16px;
            height: 40px;
            text-align: center;
            line-height: 40px;
            border: #e4e4e4 1px solid;
            border-radius: 3px;
            font-size: 14px;
        }

        .page a:hover {
            background-color: #223fd5;
            border: #223fd5 1px solid;
            color: #fff;
        }

        .page li.active span {
            background-color: #223fd5;
            border: #223fd5 1px solid;
            margin-left: 5px;
            vertical-align: top;
            padding: 0 16px;
            height: 40px;
            text-align: center;
            line-height: 40px;
            color: #fff;
            border-radius: 3px;
            font-size: 14px;
        }

        .page span {
            display: inline-block;
            margin-left: 5px;
            line-height: 32px;
            vertical-align: top;
        }
    </style>
    <div class="proper">
        <div class="calss_box f_l">
            <h1><span><a href="javascript:;" id="clear_search">清除</a></span>物业类型</h1>
            <ul class="dxk">
                <?php if (isset($propertiesCategory)) { ?>
                    <?php foreach ($propertiesCategory as $key => $val) { ?>
                        <li>
                            <label>
                                <input name="category"
                                       type="checkbox" <?php if (isset($search['category']) && !empty($search['category']) && in_array($val['id'], $search['category'])) {
                                    echo "checked";
                                } ?> value="<?php echo $val['id']; ?>"
                                       onchange="checkBox('category',<?php echo $val['id']; ?>)"/><?php echo $val['category_name']; ?>
                            </label>
                        </li>
                    <?php } ?>
                <?php } ?>
            </ul>
            <h1>建筑面积（SF）</h1>
            <ul class="ink">
                <li>
                    <input min="0" type="text" name="area" id="areaStart"
                           value="<?php if (isset($search['areaStart'])) {
                               echo $search['areaStart'];
                           } ?>">
                    <em>至</em>
                    <input min="0" type="text" name="area" id="areaEnd" onblur="areaBox()"
                           value="<?php if (isset($search['areaEnd'])) {
                               echo $search['areaEnd'];
                           } ?>">
                </li>
            </ul>
            <h1>价格范围（$）</h1>
            <ul class="ink">
                <li>
                    <input min="0" type="text" name="price" id="priceStart"
                           value="<?php if (isset($search['priceStart'])) {
                               echo $search['priceStart'];
                           } ?>">
                    <em>至</em>
                    <input min="0" type="text" name="price" id="priceEnd" onblur="priceBox()"
                           value="<?php if (isset($search['priceEnd'])) {
                               echo $search['priceEnd'];
                           } ?>">
                </li>
            </ul>
            <h1>附加选项</h1>
            <ul class="fxk">
                <li>
                    <label>
                        <input name="real" type="checkbox"
                               onchange="attachBox('real')" <?php if (isset($search['real']) && $search['real'] == 1) {
                            echo "checked";
                        } ?>>显示投资物业
                    </label>
                </li>
                <li>
                    <label>
                        <input name="auction" type="checkbox"
                               onchange="attachBox('auction')" <?php if (isset($search['auction']) && $search['auction'] == 1) {
                            echo "checked";
                        } ?> >展览拍卖
                    </label>
                </li>
                <li>
                    <label>
                        <input name="distressed" type="checkbox"
                               onchange="attachBox('distressed')" <?php if (isset($search['distressed']) && $search['distressed'] == 1) {
                            echo "checked";
                        } ?> >显示distressed
                    </label>
                </li>
            </ul>
            <h1>可用空间（RSF）</h1>
            <ul class="ink">
                <li>
                    <input min="0" type="text" name="space" id="spaceStart"
                           value="<?php if (isset($search['spaceStart'])) {
                               echo $search['spaceStart'];
                           } ?>">
                    <em>至</em>
                    <input min="0" type="text" name="space" id="spaceEnd" onblur="spaceBox()"
                           value="<?php if (isset($search['spaceEnd'])) {
                               echo $search['spaceEnd'];
                           } ?>">
                </li>
            </ul>
            <h1>租赁费率（$ / SF / YR）</h1>
            <ul class="ink">
                <li>
                    <input min="0" type="text" name="rate" id="rateStart"
                           value="<?php if (isset($search['rateStart'])) {
                               echo $search['rateStart'];
                           } ?>">
                    <em>至</em>
                    <input min="0" type="text" name="rate" id="rateEnd" onblur="rateBox()"
                           value="<?php if (isset($search['rateEnd'])) {
                               echo $search['rateEnd'];
                           } ?>">
                </li>
            </ul>
            <h1>附加选项</h1>
            <ul class="fxk">
                <li>
                    <label>
                        <input name="option" type="checkbox"
                               onchange="attachBox('option')" <?php if (isset($search['option']) && $search['option'] == 1) {
                            echo "checked";
                        } ?>>显示转租
                    </label>
                </li>
            </ul>
        </div>
        <div class="lists f_r">
            <div class="title">
                <dl>
                    <dt>
                        <a href="javascript:;" class="<?php if (isset($search['status']) && $search['status'] == 0) {
                            echo 'on';
                        } ?>" class="on" status="0" onclick="statusBox(0)">全部</a>
                        <a href="javascript:;" class="<?php if (isset($search['status']) && $search['status'] == 1) {
                            echo 'on';
                        } ?>" status="1" onclick="statusBox(1)">待售</a>
                        <a href="javascript:;" class="<?php if (isset($search['status']) && $search['status'] == 2) {
                            echo 'on';
                        } ?>" status="2" onclick="statusBox(2)">出租</a>
                    </dt>
                    <dd>
                        <select onchange="orderBox(this.options[this.options.selectedIndex].value)">
                            <option value="update_time">更新日期</option>
                            <option value="price-desc">价格从高到低</option>
                            <option value="price-asc">价格从低到高</option>
                            <option value="space-desc">尺寸从大到小</option>
                            <option value="space-asc">尺寸从小到大</option>
                            <option value="create_time-desc">创建日期最新</option>
                            <option value="create_time-asc">创建日期最早</option>
                        </select>
                        <div class="search">
                            <span><input id="keywords" placeholder="搜索城市，州，邮政编码或地址"></span>
                            <a href="javascript:;" id="search_by">搜索</a>
                        </div>
                    </dd>
                </dl>
            </div>
            <div class="wuye_list">
                <ul>
                    <?php if ($products) : ?>
                        <?php foreach ($products as $key => $val) : ?>
                            <li>
                                <div class="wuye_box">
                                    <a href="<?php echo "/properties_show/" . $val['id'] . ".html"; ?>" class="pic">
                                        <img style="width: 265px;height: 125px;" src="<?php echo $val['img'] ?? ""; ?>"></a>
                                    <span class="name">
                        	<a href="<?php echo "/properties_show/" . $val['id'] . ".html"; ?>"><?php echo $val['title']; ?></a>
                            <p><?php echo $val['address'] ?? ""; ?></p>
                            <p><?php echo $val['describe'] ?? ""; ?></p>
                        </span>
                                    <span class="price">
                        	<p><strong>$<?php echo $val['rate'] ?? ""; ?></strong></p>
                            <p><?php echo $val['price'] ?? ""; ?>SF</p>
                            <p><?php echo $val['area'] ?? ""; ?>Cap Rate</p>
                            <p>Strip Center</p>
                        </span>
                                </div>
                                <div class="email_box"><a href="mailto:499013056@qq.com">Email Paul Tsakiris</a></div>
                            </li>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </ul>
            </div>
            <div class="page">
                <ul><?php echo $pagination; ?></ul>
            </div>
        </div>
    </div>
<?php $this->load->view('common/footer'); ?>